// pages/my/myIndex/myIndex.js
const App = getApp();
const utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:0,
    hasMoreData:true,
    stePage:0,
    stehasMoreData:true,
    saltedEggList:[]//咸蛋列表
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo(options.userId),
    this.getSteBoxList(options.userId)
    this.setData({
      userId:options.userId
    })
  },

  //获取个人信息
  getUserInfo:function (userId){
    utils.requestUrl({
      url:'/niu/api/weibo_getuserinfo.php',
      params: {
        markid:wx.getStorageSync('markId'),
        userid:userId
      }
    }).then((res) =>{
      console.log(res.data);
      let data = res.data;
      var chenghaoStr = (data.chenghao).substring(3);
      this.setData({
        faceurl:data.faceurl,
        sex:data.sex,
        ismine:data.ismine,
        nick:data.nick,
        chenghaoStr:chenghaoStr,
        uservip:data.uservip,
        blackcount:data.blackcount,
        set2:data.set2
      })
    })
  },
  //获取咸蛋列表
  getSteBoxList:function (userId) {
    let that = this;
    let page = that.data.stePage
    utils.requestUrl({
      url:'/niu/apiv3/xiandan_getmylist.php',
      params:{
        markid:wx.getStorageSync('markId'),
        userid:userId,
        page:page,
        userpage:'1'
      }
    }).then((res) =>{
      console.log(res);
      var contentListTem = that.data.saltedEggList;
        if (res.data.datacount == 0 || res.data.datacount == null) {
          that.setData({
            noContent:true,
            stehasMoreData:false
          })
        }else{
          that.setData({
            noContent:false,
            stehasMoreData:true
          })
        }
        if (res.data.datacount > 0) {
          var contentList = res.data.data
          

          if (contentList.length < res.data.pagesize) {
            that.setData({
              saltedEggList:contentListTem.concat(contentList),
              stehasMoreData: false
            })
          }else{
            that.setData({
              saltedEggList: contentListTem.concat(contentList),
              stehasMoreData: true,
              stePage: page + 1
          })
          }
        }
    })
  },
  //去往详情
  goToDetail:function (e) {
    let id = e.currentTarget.dataset.id
    console.log(id);
    wx.navigateTo({
      url: '/pages/used/usedDetail/usedDetail?id='+id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // if(wx.getStorageSync('markId') == ''){
    //   wx.navigateTo({
    //     url: '/pages/login/login',
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.stehasMoreData) {
      this.getSteBoxList(userId)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var userId = this.data.userId;
    return {
      title: '咸蛋分享',
      path: '/pages/my/myWarehouseShare/myWarehouseShare?userId='+userId,
      imageUrl:'https://api.odancool.com/weixinapp/res/img/common/shareImg.png'
    }
  }
})